package com.young.core.enums;

/**
 * 任务分发、执行的状态；此类存在新旧版本兼容性
 * 原则上，success应该为大于1，失败类型的应该小于0；但是历史问题，我们通过standard值进行综合转换
 */
public enum HttpStatusEnum {

    /**
     * 新旧版本兼容，status值合并统一
     */

    /**
     * u:upstream,d:downstream
     */
    D_FAILURE(2, -4,"执行失败"),
    U_JOB_MISS(1, -3,"未找到"),
    U_PARAMETER_ERROR(-1, -2,"调度参数或方法有问题"),
    U_HTTP_ERROR(-2, -1,"请求失败"),


    U_SUCCESS(0, 1,"调度成功"),
    D_SUCCESS(1, 2,"执行成功");

    public int facade;//客户端返回值

    public int standard;//入库的标准值

    public String meaning;

    static HttpStatusEnum[] UFS = {U_JOB_MISS, U_PARAMETER_ERROR, U_HTTP_ERROR,U_SUCCESS};
    static HttpStatusEnum[] DFS = {D_FAILURE,D_SUCCESS};

    HttpStatusEnum(int facade, int standard, String meaning) {
        this.facade = facade;
        this.standard = standard;
        this.meaning = meaning;
    }

    public static HttpStatusEnum uf(Integer facade) {
        if (facade == null) {
            return null;
        }
        for (HttpStatusEnum e : UFS) {
            if (e.facade == facade) {
                return e;
            }
        }
        return null;
    }

    public static HttpStatusEnum df(Integer facade) {
        if (facade == null) {
            return null;
        }
        for (HttpStatusEnum e : DFS) {
            if (e.facade == facade) {
                return e;
            }
        }
        return null;
    }

    public static boolean isUSuccess(int facade) {
        return facade == U_SUCCESS.facade || facade == U_JOB_MISS.facade;
    }

    /**
     * 是否为标准成功值
     * @param standard
     * @return
     */
    public static boolean isSSuccess(int standard) {
        return standard == D_SUCCESS.standard;
    }

    public static boolean isDSuccess(int facade) {
        return facade == D_SUCCESS.facade;
    }
}